package com.yanqu.road.entity.activity.sonhai.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

@FieldTypeAnnotation(tableName = "t_c_activity_son_hai_activity_data")
public class SonHaiActivityData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "分组ID", select = true, update = true)
    private int groupId;

    @FieldTypeAnnotation(desc = "最大区域唯一ID")
    private AtomicInteger maxRegionUniqueId;

    @FieldTypeAnnotation(desc = "最大兽蛋奖励唯一ID")
    private AtomicInteger maxEggRewardId;

    @FieldTypeAnnotation(desc = "兽蛋重置时间")
    private long eggResetTime;

    @FieldTypeAnnotation(desc = "区服vip战力数据MAP，k：区服，k：vip等级，v：战力均值")
    private Map<Long, Map<Integer, SonHaiVipAvePowerData>> serverAvePowerMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "vip分布均值战力，k:vip等级，v：战力均值")
    private Map<Integer, Long> vipAvePowerMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "活动结束-同步区服更新队伍积分时间")
    private long updateTeamScoreTime;

    @FieldTypeAnnotation(desc = "补发蛋蛋奖励时间")
    private long bfEggRewardTime;

    public SonHaiActivityData() {}

    public SonHaiActivityData(int activityId, int groupId) {
        this.activityId = activityId;
        this.groupId = groupId;
        this.maxRegionUniqueId = new AtomicInteger(0);
        this.maxEggRewardId = new AtomicInteger(0);
        this.eggResetTime = 0;
        this.updateTeamScoreTime = 0;
        this.bfEggRewardTime = 0;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        if (this.groupId != groupId) {
            this.groupId = groupId;
            setOp(DataStatus.Update);
        }
    }

    public AtomicInteger getMaxRegionUniqueId() {
        return maxRegionUniqueId;
    }

    public int getMaxRegionUniqueIdAndAdd() {
        int value = this.maxRegionUniqueId.incrementAndGet();
        setOp(DataStatus.Update);
        return value;
    }

    public void setMaxRegionUniqueId(AtomicInteger maxRegionUniqueId) {
        if (null == maxRegionUniqueId){
            return;
        }
        if (this.maxRegionUniqueId == null || !this.maxRegionUniqueId.equals(maxRegionUniqueId)) {
            this.maxRegionUniqueId = maxRegionUniqueId;
            setOp(DataStatus.Update);
        }
    }

    public AtomicInteger getMaxEggRewardId() {
        return maxEggRewardId;
    }

    public int getMaxEggRewardIdAndAdd() {
        int value = this.maxEggRewardId.incrementAndGet();
        setOp(DataStatus.Update);
        return value;
    }

    public void setMaxEggRewardId(AtomicInteger maxEggRewardId) {
        if (null == maxEggRewardId){
            return;
        }
        if (this.maxEggRewardId == null || !this.maxEggRewardId.equals(maxEggRewardId)) {
            this.maxEggRewardId = maxEggRewardId;
            setOp(DataStatus.Update);
        }
    }

    public long getEggResetTime() {
        return eggResetTime;
    }
    public void setEggResetTime(long eggResetTime) {
        if (this.eggResetTime != eggResetTime) {
            this.eggResetTime = eggResetTime;
            setOp(DataStatus.Update);
        }
    }

    public Map<Long, Map<Integer, SonHaiVipAvePowerData>> getServerAvePowerMap() {
        return serverAvePowerMap;
    }

    public void setServerAvePowerMap(Map<Long, Map<Integer, SonHaiVipAvePowerData>> serverAvePowerMap) {
        this.serverAvePowerMap = serverAvePowerMap;
    }

    public void addServerAvePowerMap(long serverId, Map<Integer, SonHaiVipAvePowerData> serverAvePowerMap) {
        this.serverAvePowerMap.put(serverId, serverAvePowerMap);
        setOp(DataStatus.Update);
    }

    public Map<Integer, Long> getVipAvePowerMap() {
        return vipAvePowerMap;
    }

    public void setVipAvePowerMap(Map<Integer, Long> vipAvePowerMap) {
        this.vipAvePowerMap = vipAvePowerMap;
        setOp(DataStatus.Update);
    }

    public long getUpdateTeamScoreTime() {
        return updateTeamScoreTime;
    }

    public void setUpdateTeamScoreTime(long updateTeamScoreTime) {
        this.updateTeamScoreTime = updateTeamScoreTime;
        setOp(DataStatus.Update);
    }

    public long getBfEggRewardTime() {
        return bfEggRewardTime;
    }

    public void setBfEggRewardTime(long bfEggRewardTime) {
        if (this.bfEggRewardTime != bfEggRewardTime) {
            this.bfEggRewardTime = bfEggRewardTime;
            setOp(DataStatus.Update);
        }
    }
}
